package com.robot.console.util;

import java.util.LinkedList;

/**
 * The queue where all the work is placed.
 * <p>
 * Title: 123 Flash Chat Server
 * </p>
 * <p>
 * Description: 123 Flash Chat Server Standard Version
 * </p>
 * <p>
 * Copyright: Copyright (c) 2003 - 2005
 * </p>
 * <p>
 * Company: TopCMM
 * </p>
 * 
 * @author Daniel Jiang
 * @version 4.5
 */
class WorkQueue
{
	@SuppressWarnings("rawtypes")
	private LinkedList work;
	private boolean debug = false;

	@SuppressWarnings("rawtypes")
	public WorkQueue()
	{
		work = new LinkedList();
	}

	@SuppressWarnings("unchecked")
	public synchronized void addWork(Runnable task)
	{
		if (debug)
		{
			int n = work.size();
			if (n > 0)
			{
				// System.out.println("work size:" + n);
			}
		}
		work.add(task);
		notify();
	}

	public synchronized Object getWork() throws InterruptedException
	{
		while (work.isEmpty())
		{
			try
			{
				wait();
			}
			catch (InterruptedException ie)
			{
				throw ie;
			}
		}
		return work.remove(0);
	}
}
